-- mysql_test.lua
local log_debug = logger.debug

local timer_mgr = quanta.get("timer_mgr")

local MysqlMgr  = import("store/mysql_mgr.lua")
local mysql_mgr = MysqlMgr()

timer_mgr:once(3000, function()
    log_debug("mysql db start test!")
    local code, res_oe = mysql_mgr:query(1, "drop table test_mysql")
    log_debug("db drop table code: {}, res = {}", code, res_oe)
    code, res_oe = mysql_mgr:query(1, "create table if not exists test_mysql (id int auto_increment, pid int, value int, primary key (id))")
    log_debug("db create table code: {}, res = {}", code, res_oe)
    code, res_oe = mysql_mgr:query(1, "insert into test_mysql (pid, value) values (123457, 40)")
    log_debug("db insert code: {}, res_oe = {}", code, res_oe)
    code, res_oe = mysql_mgr:query(1, "insert into test_mysql (pid, value) values (123456, 40)")
    log_debug("db insert code: {}, res_oe = {}", code, res_oe)
    code, res_oe = mysql_mgr:query(1, "select count(*) as count from test_mysql where pid=123457")
    log_debug("db select code: {}, count = {}", code, res_oe)
    code, res_oe = mysql_mgr:query(1, "select * from test_mysql where pid = 123456")
    log_debug("db select code: {}, res_oe = {}", code, res_oe)
    code, res_oe = mysql_mgr:query(1, "update test_mysql set pid = 123454, value = 20 where pid = 123456 limit 1")
    log_debug("db update code: {}, err = {}", code, res_oe)
    code, res_oe = mysql_mgr:query(1, "select * from test_mysql")
    log_debug("db select code: {}, res_oe = {}", code, res_oe)
    code, res_oe = mysql_mgr:query(1, "delete from test_mysql where pid = 123457")
    log_debug("db delete code: {}, err = {}", code, res_oe)
    code, res_oe = mysql_mgr:query(1, "replace into test_mysql (id, pid, value) values (1, 123457, 40)")
    log_debug("db replace code: {}, count = {}", code, res_oe)
    code, res_oe = mysql_mgr:query(1, "select * from test_mysql")
    log_debug("db select code: {}, res_oe = {}", code, res_oe)
    code, res_oe = mysql_mgr:query(1, "select count(*) as count from test_mysql where pid=123454")
    log_debug("db count code: {}, count = {}", code, res_oe)
end)